/*
 * Created by JFormDesigner on Tue Jul 02 08:01:48 CST 2024
 */

package scct.yzx.ui;

import scct.yzx.dao.ConversationDao;
import scct.yzx.model.Conversation;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author lenovo
 */
public class DlgConversationDelete extends JDialog {
     int id;

    public DlgConversationDelete(Window owner,int id) {
        super(owner);
        this.id = id;
        initComponents();
        initView();

    }

    private void initView() {
        ConversationDao conversationDao=new ConversationDao();
        Conversation conversation=conversationDao.getConversationId(id);
    }


    private void btnDelete(ActionEvent e) {
        // TODO add your code here
        ConversationDao conversationDao=new ConversationDao();
        if (conversationDao.deleteConversation(id)) {
            JOptionPane.showMessageDialog(this,"删除成功");
            dispose();
            return;
        }

    }

    private void btnCancle(ActionEvent e) {
        // TODO add your code here
       this.dispose();
    }



    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - yzx
        label1 = new JLabel();
        btnDelete = new JButton();
        btnCancle = new JButton();

        //======== this ========
        setTitle("\u5220\u9664\u4f1a\u8bdd");
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u786e\u5b9a\u5220\u9664\u6b64\u4f1a\u8bdd");
        contentPane.add(label1);
        label1.setBounds(115, 40, 135, 55);

        //---- btnDelete ----
        btnDelete.setText("\u5220\u9664");
        btnDelete.addActionListener(e -> btnDelete(e));
        contentPane.add(btnDelete);
        btnDelete.setBounds(new Rectangle(new Point(65, 130), btnDelete.getPreferredSize()));

        //---- btnCancle ----
        btnCancle.setText("\u53d6\u6d88");
        btnCancle.addActionListener(e -> btnCancle(e));
        contentPane.add(btnCancle);
        btnCancle.setBounds(new Rectangle(new Point(200, 130), btnCancle.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(400, 300);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - yzx
    private JLabel label1;
    private JButton btnDelete;
    private JButton btnCancle;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
